package com.heng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heng.dao.entity.coupon.CouponTemplateLogEntity;
import com.heng.service.CouponTemplateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/coupon-template-logs")
public class CouponTemplateLogController {

    @Autowired
    private CouponTemplateLogService logService;

    // 新增操作日志（自动记录，无需手动调用）
    @PostMapping
    public boolean addLog(@RequestBody CouponTemplateLogEntity logEntity) {
        return logService.save(logEntity);
    }

    // 按ID查询日志
    @GetMapping("/{id}")
    public CouponTemplateLogEntity getLogById(@PathVariable Long id) {
        return logService.getById(id);
    }

    // 按模板ID查询日志
    @GetMapping("/template/{couponTemplateId}")
    public List<CouponTemplateLogEntity> getByTemplateId(@PathVariable String couponTemplateId) {
        return logService.getByTemplateId(couponTemplateId);
    }

    // 按操作人查询日志
    @GetMapping("/operator/{operatorId}")
    public List<CouponTemplateLogEntity> getByOperatorId(@PathVariable String operatorId) {
        return logService.getByOperatorId(operatorId);
    }

    // 分页查询日志
    @GetMapping("/page")
    public IPage<CouponTemplateLogEntity> pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return logService.pageQuery(pageNum, pageSize);
    }
}